package com.shopoo.behavior.infrastructure.database.mapper;

import java.util.List;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.shopoo.behavior.infrastructure.database.dataobject.TBehaviorShare;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * File Name:ShareMapper.java Package Name:com.szmengran.behavior.mapper
 * 
 * @TODO:
 * @author <a href="mailto:android_li@sina.cn">LiMaoYuan</a> Copyright (c) 2019,
 *         深圳市梦燃科技有限公司 All Rights Reserved.
 * @createTime 2019年6月3日下午5:03:18
 */
@Mapper
public interface ShareMapper<T> extends BaseMapper<T> {

    /**
     * 增加阅读量
     * 
     * @param promotionid
     * @param userid
     * @return
     * @throws Exception
     * @author <a href="mailto:android_li@sina.cn">LiMaoYuan</a> Copyright (c) 2019,
     *         深圳市梦燃科技有限公司 All Rights Reserved.
     * @createTime 2019年6月3日下午5:09:40
     */
    @Update("update t_behavior_share set readCount = readCount+1 where promotionid=#{promotionid} and userid=#{userid}")
    int addRead(@Param("promotionid") String promotionid, @Param("userid") String userid);

    /**
     * 点赞
     * 
     * @param promotionid
     * @param userid
     * @return
     * @throws Exception
     * @author <a href="mailto:android_li@sina.cn">Joe</a>
     */
    @Update("update t_behavior_share set likeCount = likeCount+1 where promotionid=#{promotionid} and userid=#{userid}")
    int addLike(@Param("promotionid") String promotionid, @Param("userid") String userid);

    /**
     * 取消点赞
     * 
     * @param promotionid
     * @param userid
     * @return
     * @throws Exception
     * @author <a href="mailto:android_li@sina.cn">Joe</a>
     */
    @Update("update t_behavior_share set likeCount = likeCount-1 where promotionid=#{promotionid} and userid=#{userid}")
    int cancelLike(@Param("promotionid") String promotionid, @Param("userid") String userid);

    /**
     * 根据传单ID查询用户的点赞信息，并进行排序
     * 
     * @param promotionid
     * @return
     * @throws Exception
     * @author <a href="mailto:android_li@sina.cn">LiMaoYuan</a> Copyright (c) 2019,
     *         深圳市梦燃科技有限公司 All Rights Reserved.
     * @createTime 2019年6月4日下午1:27:28
     */
    @Select("select * from t_behavior_share where promotionid=#{promotionid}")
    List<TBehaviorShare> findByPromotionid(@Param("promotionid") String promotionid);
}
